const http = require('./request.js')

module.exports = {
  // 获取商品总数
  getCount: function() {
    return http('goods/count').then(res=>{
      return res.data;
    })
  },
  // 获取首页数据
  getIndex: function() {
    return http('index/index').then(res => {
      return res.data;
    })
  },
  // 获取专题列表
  getTopicList(params) {
    return http('topic/list',{},'GET',params).then(res => {
      return res.data;
    })
  },
  // 获取分类列表
  getClassifyList() {
    return http('catalog/index').then(res => {
      return res.data
    })
  },
  // 获取分类详情
  getClassifyDetails(id) {
    return http('catalog/current',{},'GET',{
      id
    }).then(res => res.data)
  },
  // 获取商品详情
  getGoodsDetail(id) {
    // return http('goods/detail', {}, 'GET', { id }).then(res => res.data)
    return http('goods/detail?id='+ id).then(res => res.data)
  },
  //获取评论接口
  getComments(obj) {
    return http('comment/list', {}, 'GET', {
      typeId: 0,
      showType: 0,
      ...obj
    }).then(res => res.data)
  },
  //获取评论数
  getCommentsCount(id) {
    return http('comment/count', {}, 'GET', {
      valueId: id,
      typeId: 0
    }).then(res => res.data)
  },
  // 大家都在看
  getRelated(id) {
    return http('goods/related?id='+id).then(res => res.data)
  },
  // 加入购物车
  joinCart(obj) {
    return http('cart/add',obj,'POST').then(res => {
      wx.showToast({
        title: '加入购物车成功',
      })
      return res.data;
    })
  },
  // 获取购物车商品数量
  getCartCount() {
    return http('cart/goodscount').then(res => res.data)
  },
  // 收藏商品
  collectGoods(obj) {
    return http('collect/addordelete',obj,'POST').then(res => {
      return res.data
    })
  },
  // 微信登录
  loginByWeixin(obj) {
    return http('auth/loginByWeixin',obj,'POST').then(res => {
      wx.showToast({
        title: '登录成功',
      })
      return res.data
    })
  },
  // 获取购物车商品
  getCartGoods() {
    return http('cart/index').then(res => res.data)
  },
  // 选中商品
  cartChecked(obj) {
    return http('cart/checked',obj,'POST').then(res => res.data)
  },
  // 删除购物车商品
  deleteCartGoods(productIds) {
    return http('cart/delete',{productIds},'POST').then(res => res.data)
  },
  // 购物车数据加减
  updateCartGoods(obj) {
    return http('cart/update',obj,'POST').then(res => res.data)
  },
  // 搜索页默认进入请求接口
  searchDefault() {
    return http('search/index').then(res => res.data)
  },
  // 搜索帮助
  searchHelper(val) {
    return http('search/helper?keyword='+val).then(res => res.data)
  },
  // 获取商品列表
  getGoodList(obj) {
    return http('goods/list',{},'GET',obj).then(res => res.data)
  }
}